package com.aviva.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.core.io.ClassPathResource;

@Configuration
@Import({MailSenderConfig.class,RepositoryConfig.class})
@Profile(value = "dev")
@ComponentScan("com.aviva")
//@ImportResource(value={"classpath:/spring.xml"})
public class AppConfig {
	@Autowired
	private Environment env;
//	@Value("${mail.host}")
//	private String mailHost;
//	@Value("${mail.port}")
//	private String mailPort;

	public AppConfig() {
		System.out.println("......appconfig.......");
	}
	
	@Bean
	public static PropertyPlaceholderConfigurer getPropertyPlaceholderConfigurer() {
		PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
		ClassPathResource resource = new ClassPathResource("app-"+AppInitializer.env+".properties");
		ppc.setLocation(resource);
		ppc.setIgnoreUnresolvablePlaceholders(true);
		return ppc;
	}
//	@Bean(name="cacheManager")
//	public static SpringEmbeddedCacheManagerFactoryBean getCacheManager() {
//		SpringEmbeddedCacheManagerFactoryBean cacheManagerFactoryBean = new SpringEmbeddedCacheManagerFactoryBean();
//		cacheManagerFactoryBean.setConfigurationFileLocation(new ClassPathResource("infinispan.xml"));
//		return cacheManagerFactoryBean;
//	}

//	@Bean(name="mailSender")
//	JavaMailSenderImpl getMailSender() {
//		//String property = env.getProperty("mail.host");
//		JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
//		mailSender.setHost(mailHost);
//		mailSender.setPort(Integer.parseInt(mailPort));
//		return mailSender;
//	}
	

}
